package com.emm.yixun.mobile.ui.subscribe;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.adapter.AnnexAdapter;
import com.emm.yixun.mobile.adapter.JJAdapter;
import com.emm.yixun.mobile.adapter.NewFromAdapter;
import com.emm.yixun.mobile.adapter.PhoneSelectAdapter;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.fragment.CustomerFragment;
import com.emm.yixun.mobile.model.AddSubscribe;
import com.emm.yixun.mobile.model.AddpirModel;
import com.emm.yixun.mobile.model.GetConsultantList;
import com.emm.yixun.mobile.model.GetCustomerDetail;
import com.emm.yixun.mobile.model.GetCustomerList;
import com.emm.yixun.mobile.model.GetDictionaryList.RqBusNumList;
import com.emm.yixun.mobile.model.GetHousesDetail;
import com.emm.yixun.mobile.model.GetRecommendCustomerListHander;
import com.emm.yixun.mobile.model.GetSubscribeDetail;
import com.emm.yixun.mobile.model.NewClassKehuModel;
import com.emm.yixun.mobile.model.NewGetDictionaryList;
import com.emm.yixun.mobile.ui.CustomerListActivity;
import com.emm.yixun.mobile.ui.housing.HousingresourcesActivity;
import com.emm.yixun.mobile.ui.signed.NewSignedActivity;
import com.emm.yixun.mobile.ui.signed.NewSignedActivity.ImageListInfo;
import com.emm.yixun.mobile.ui.signed.NewSignedActivity.JJInfo;
import com.emm.yixun.mobile.ui.signed.NewSignedActivity.dealCategoryList;
import com.eroad.product.tools.MyGridView;
import com.eroad.product.tools.MyListView;
import com.eroad.product.tools.PickerView;
import com.eroad.product.tools.PickerView.onSelectListener;
import com.eroad.product.tools.PopuContent;
import com.eroad.product.tools.Time_SelectPicPopupWindow;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nui.multiphotopicker.model.ImageItem;
import com.nui.multiphotopicker.view.ImageBucketChooseActivity;
import com.yanzhenjie.album.Album;
import com.yixun.app.viewpagerandimag.sample.ViewPagerActivity;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import xf.tools.Loading;
import xf.tools.popu.SelectPicPopupWindow_Test;

/**
 * <p>
 * <b>Title：</b> 新增认购/认筹转认购
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 *
 * @author tangxin
 * @date 2016年12月6日 下午4:09:33
 */
public class NewSubscribeActivity extends BaseActivity {

    private static final String TAG = "NewSubscribeActivity";
    public static final String HOUSE_DETAIL = "HOUSE_DETAIL";
    public static final String ROOM_ID = "ROOM_ID";

    /**
     * 1新增 非1修改 5代表有房认筹转认购 12修改
     */
    private String OpenType = "1";

    /**
     * 房源ID
     */
    private String FrdID = "";

    /**
     * 折扣比例
     */
    private String Hdnumber = "0";

    /**
     * 折扣金额
     */
    private String Hdprice = "0";

    /**
     * 审批是否显示 true 显示 false 隐藏
     */
    private boolean IsDis = false;

    /**
     * 认筹ID
     */
    private String payDepositId = "";

    /**
     * 认筹编号
     */
    private String payDepositCode = "";

    /**
     * 认筹金
     */
    private String payDepositMoney = "";

    /**
     * 认购业务ID
     */
    private String subscribeId = "";

    /**
     * 认购房源
     */
    EditText housing_btn;

    /**
     * 客户ID
     */
    private String customerId = "";

    /**
     * 添加客户
     */
    ImageView add;

    ArrayList<NewClassKehuModel> list = new ArrayList<NewClassKehuModel>();
    NewFromAdapter adapter;
    MyListView kehuxinxi;

    /**
     * 房源信息
     */
    private boolean IsFangyuan = true;

    /**
     * 客户信息
     */
    private boolean IsKehu = true;

    /**
     * 房源信息
     */
    LinearLayout fangyuan, fangyuan_layout;

    /**
     * 客户信息
     */
    LinearLayout kehu, kehu_layout;

    ImageView rt1, rt2;

    /**
     * 保存
     */
    TextView is_sure;

    /**
     * 提交审核
     */
    TextView reject_btn;

    /**
     * 证件类型
     */
    EditText zj_type;

    /* ---公用选择框--- */
    View view;

    PopupWindow popu;

    /**
     * 选中内容
     */
    String selectName;

    /**
     * 选中下标
     */
    int SelectID;

    ArrayList<String> listname;
    /* ---公用选择框--- */

    /**
     * 选择地址显示view
     */
    EditText addr_ed;

    /**
     * 自定义地址选择器
     */
    private SelectPicPopupWindow_Test popupWindow_Test;

    /**
     * 自定义时间控件
     */
    private Time_SelectPicPopupWindow time_SelectPicPopupWindow;

    /**
     * 选择时间显示view
     */
    EditText time_ed;

    /**
     * 选择地址
     */
    EditText select_address;

    TextView title_main;

    ImageView back_btn;

    /**
     * 认购转合同到期日期
     */
    EditText p_from_time;

    /**
     * 认购日期
     */
    EditText rg_times;

    /**
     * 支付方式
     */
    EditText pay_type;

    /**
     * 成交类别
     */
    EditText cj_type;

    /**
     * 经纪人
     */
    EditText p_jjrmine;

	/*------------------------------*/
    /**
     * 认购编号
     */
    EditText rengou_code;

    /**
     * 计价面积
     */
    EditText valuation_area;

    /**
     * 折前单价
     */
    EditText folding_front_unit_price;

    /**
     * 折前总价
     */
    EditText discountTotalPrice_view;

    /**
     * 客户姓名
     */
    EditText customerName_view;

    /**
     * 证件号码
     */
    EditText peDocumentNumber_view;

    /**
     * 手机号码
     */
    EditText customerPhone_view;

    /**
     * 邮编
     */
    EditText pePostcode_view;

    /**
     * 折扣金额
     */
    EditText discountAmount_view;

    /**
     * 折扣总价
     */
    EditText discountAmount_all_view;

    /**
     * 折扣比例
     */
    EditText discountRate_view;

    /**
     * 折扣说明
     */
    EditText discountNote_view;

    /**
     * 签约单价
     */
    EditText contractPrice_view;

    /**
     * 合同金额
     */
    EditText contractAmount_view;

    /**
     * 应收定金
     */
    EditText depositReceivable_view;

    /**
     * 备注
     */
    EditText remark_view;

    /**
     * 优惠原因
     */
    EditText youhui_view;

    /**
     * 折扣原因
     */
    LinearLayout is_code1;

    /**
     * 提示内容
     */
    LinearLayout is_code2;

    /**
     * 当前百分比
     */
    TextView number1;

    /**
     * 浮动值百分比
     */
    TextView number2;

    View line_type_for_code;

    LinearLayout discountAmount_all_view_linear;

	/*------------------------------*/

    MyListView jj_list;

    ImageView open_icon;

    /**
     * 认筹转认购金额
     */
    String realAmount;

    EditText realAmount_view;

    LinearLayout realAmount_linearlayout;

    TextView realAmount_name_view;

    LinearLayout reference_linear_layout;

    /**
     * 推荐人
     */
    EditText referenceName;

    ImageView more_referenceName;

    /**
     * 推荐人分佣比例
     */
    EditText referenceProportion;

    /**
     * 图片附件
     */
    TextView from_htsm_view;

    /**
     * 图片附件grid
     */
    MyGridView grid_phone;

    ArrayList<AddpirModel> ap;

    ArrayList<AddpirModel> ap2 = new ArrayList<AddpirModel>();

    /**
     * 合同扫描适配器
     */
    PhoneSelectAdapter padapter;

    /**
     * 附件布局
     */
    LinearLayout annex_layout;

    /**
     * 附件列表
     */
    MyListView annexList_list;

    /**
     * 附件数量
     */
    TextView annexNum_view;

    /**
     * 用于监听最外层布局高度，判断键盘弹出不展示保存和提交审核的底部菜单
     */
    RelativeLayout background_key;

    /**
     * 底部菜单布局
     */
    LinearLayout buttom_select;

    GetHousesDetail houseDetail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        IsVisibleStatusBar = false;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_subscribe_activity);
        BaseActivity.activity = this;

        OpenType = getIntent().getStringExtra("OpenType");
        customerId = getIntent().getStringExtra("customerId");
        payDepositId = getIntent().getStringExtra("payDepositId");
        payDepositCode = getIntent().getStringExtra("payDepositCode");
        payDepositMoney = getIntent().getStringExtra("payDepositMoney");
        subscribeId = getIntent().getStringExtra("subscribeId");
        realAmount = getIntent().getStringExtra("realAmount");

        FrdID = getIntent().getStringExtra(ROOM_ID);
        houseDetail = (GetHousesDetail) getIntent().getSerializableExtra(HOUSE_DETAIL);

        initView();

        findViewById(R.id.statusbar_bg).setVisibility(View.GONE);
        // SetRelativiLayoutPadding(R.id.main_head_top_rela);

        initBtn();
        setHouseDetail();

        rg_times.setText(EmmApplication.dataTime(EmmApplication.geTime(), "yyyy年MM月dd日"));

        if (EmmApplication.isNull(realAmount)) {
            realAmount_linearlayout.setVisibility(View.VISIBLE);
            realAmount_view.setText(realAmount);
        } else {
            realAmount_linearlayout.setVisibility(View.GONE);
        }

        if ("1".equals(OpenType)) {// 新增认购
            if (houseDetail == null) getCustomerDetail(customerId);
            getConsultantList(1);
        } else if ("5".equals(OpenType)) {// 有房认筹转认购
            if (houseDetail == null) getCustomerDetail(customerId);
            housing_btn.setEnabled(false);
            getConsultantList(1);
        } else {// 修改
            getConsultantList(7);
        }

        getDictionaryList();
    }

    /**
     * <p>
     * <b>Title：</b> 初始化view
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:59:13
     */
    private void initView() {
        housing_btn = (EditText) findViewById(R.id.housing_btn);
        add = (ImageView) findViewById(R.id.add);
        kehuxinxi = (MyListView) findViewById(R.id.kehuxinxi);
        fangyuan = (LinearLayout) findViewById(R.id.fangyuan);
        fangyuan_layout = (LinearLayout) findViewById(R.id.fangyuan_layout);
        rt1 = (ImageView) findViewById(R.id.rt1);
        kehu = (LinearLayout) findViewById(R.id.kehu);
        kehu_layout = (LinearLayout) findViewById(R.id.kehu_layout);
        rt2 = (ImageView) findViewById(R.id.rt2);
        zj_type = (EditText) findViewById(R.id.zj_type);
        select_address = (EditText) findViewById(R.id.select_address);
        title_main = (TextView) findViewById(R.id.title_main);
        back_btn = (ImageView) findViewById(R.id.back_btn);
        p_from_time = (EditText) findViewById(R.id.p_from_time);
        rg_times = (EditText) findViewById(R.id.rg_times);
        pay_type = (EditText) findViewById(R.id.pay_type);
        cj_type = (EditText) findViewById(R.id.cj_type);
        p_jjrmine = (EditText) findViewById(R.id.p_jjrmine);
        is_sure = (TextView) findViewById(R.id.is_sure);
        reject_btn = (TextView) findViewById(R.id.reject_btn);

        rengou_code = (EditText) findViewById(R.id.rengou_code);
        valuation_area = (EditText) findViewById(R.id.valuation_area);
        folding_front_unit_price = (EditText) findViewById(R.id.folding_front_unit_price);
        discountTotalPrice_view = (EditText) findViewById(R.id.discountTotalPrice_view);
        customerName_view = (EditText) findViewById(R.id.customerName_view);
        peDocumentNumber_view = (EditText) findViewById(R.id.peDocumentNumber_view);
        customerPhone_view = (EditText) findViewById(R.id.customerPhone_view);
        pePostcode_view = (EditText) findViewById(R.id.pePostcode_view);
        discountAmount_view = (EditText) findViewById(R.id.discountAmount_view);
        discountAmount_all_view = (EditText) findViewById(R.id.discountAmount_all_view);
        discountRate_view = (EditText) findViewById(R.id.discountRate_view);
        discountNote_view = (EditText) findViewById(R.id.discountNote_view);
        contractPrice_view = (EditText) findViewById(R.id.contractPrice_view);
        contractAmount_view = (EditText) findViewById(R.id.contractAmount_view);
        depositReceivable_view = (EditText) findViewById(R.id.depositReceivable_view);
        remark_view = (EditText) findViewById(R.id.remark_view);
        youhui_view = (EditText) findViewById(R.id.youhui_view);
        realAmount_name_view = (TextView) findViewById(R.id.realAmount_name_view);
        is_code1 = (LinearLayout) findViewById(R.id.is_code1);
        is_code2 = (LinearLayout) findViewById(R.id.is_code2);
        number1 = (TextView) findViewById(R.id.number1);
        number2 = (TextView) findViewById(R.id.number2);
        line_type_for_code = findViewById(R.id.line_type_for_code);
        discountAmount_all_view_linear = (LinearLayout) findViewById(R.id.discountAmount_all_view_linear);
        jj_list = (MyListView) findViewById(R.id.jj_list);
        open_icon = (ImageView) findViewById(R.id.open_icon);
        realAmount_view = (EditText) findViewById(R.id.realAmount_view);
        realAmount_linearlayout = (LinearLayout) findViewById(R.id.realAmount_linearlayout);
        reference_linear_layout = (LinearLayout) findViewById(R.id.reference_linear_layout);

        referenceName = (EditText) findViewById(R.id.referenceName);

        more_referenceName = (ImageView) findViewById(R.id.more_referenceName);

        referenceProportion = (EditText) findViewById(R.id.referenceProportion);

        from_htsm_view = (TextView) findViewById(R.id.from_htsm_view);
        from_htsm_view.setText("图片附件");
        grid_phone = (MyGridView) findViewById(R.id.grid_phone);
        annex_layout = (LinearLayout) findViewById(R.id.annex_layout);
        annexList_list = (MyListView) findViewById(R.id.annexList_list);
        annexNum_view = (TextView) findViewById(R.id.annexNum_view);
        background_key = (RelativeLayout) findViewById(R.id.background_key);
        buttom_select = (LinearLayout) findViewById(R.id.buttom_select);
    }


    private void setHouseDetail() {
        if (houseDetail != null) {
            housing_btn.setText(houseDetail.getHousesName(), null);
            valuation_area.setText(houseDetail.getBuildingArea(), null);
            folding_front_unit_price.setText(houseDetail.getBuildingPrice(), null);
            if (!TextUtils.isEmpty(houseDetail.getTotalAmount())) {
                try {
                    String price = new DecimalFormat("0.00").format(Double.parseDouble(houseDetail.getTotalAmount()) * 10000);
                    discountTotalPrice_view.setText(price, null);
                    discountAmount_all_view.setText(price, null);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
            customerName_view.setFocusable(false);
            customerName_view.setFocusableInTouchMode(false);
            customerName_view.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivityForResult(new Intent(NewSubscribeActivity.this, CustomerListActivity.class), SELECT_CUSTOMER);
                }
            });
        }
    }

    /**
     * <p>
     * Title:根据认购日期配置要选择的认购转合同到期时间
     * </p>
     * <p>
     * Description:
     * </p>
     *
     * @author zhaofei
     * @date 2017年1月10日 上午10:29:04
     */
    private void changeRGtime() {
        String rgtime = rg_times.getText().toString().trim();
        SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar c = Calendar.getInstance();
        try {
            Date date = df.parse(rgtime);
            c.setTime(date);
            listname = new ArrayList<String>();
            listname.add(SetTimeDeta(c, 0));
            listname.add(SetTimeDeta(c, 1));
            listname.add(SetTimeDeta(c, 1));
            listname.add(SetTimeDeta(c, 1));
            listname.add(SetTimeDeta(c, 1));
            listname.add(SetTimeDeta(c, 1));
            listname.add(SetTimeDeta(c, 1));
            setZpPoPu(listname, "认购转合同到期日期选择", p_from_time);

        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    /**
     * <p>
     * Title:根据日历时间得到后一天日期的字符串
     * </p>
     * <p>
     * Description:
     * </p>
     *
     * @param calendar
     * @param number
     * @return
     * @author zhaofei
     * @date 2017年1月10日 上午11:46:39
     */
    private String SetTimeDeta(Calendar calendar, int number) {
        // add就是加的时间，如果要前一天，可以传递-1
        calendar.add(Calendar.DAY_OF_MONTH, number);
        // 获取日期格式化工具类
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        // 得到结果
        String time = sdf.format(calendar.getTime());
        return time;
    }

    /**
     * 0上限1 1上限3
     */
    private int typefound = 0;

    /**
     * <p>
     * <b>Title：</b> 初始化监听事件
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午4:00:08
     */
    private void initBtn() {
        background_key.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // 比较Activity根布局与当前布局的大小
                int heightDiff = background_key.getRootView().getHeight() - background_key.getHeight();
                if (heightDiff > 100) {
                    // 大小超过100时，一般为显示虚拟键盘事件
                    Log.v(TAG, "---------大于一百--键盘打开");
                    buttom_select.setVisibility(View.GONE);
                } else {
                    // 大小小于100时，为不显示虚拟键盘或虚拟键盘隐藏
                    Log.v(TAG, "---------小于一百--键盘关闭");
                    buttom_select.setVisibility(View.VISIBLE);
                }
            }
        });

        // 显示对应标题
        if ("1".equals(OpenType) || "5".equals(OpenType)) {
            title_main.setText(getString(R.string.set_pdgoud));
        } else {
            title_main.setText(getString(R.string.update_subscridetails));
        }

        IsOpenOrClose(fangyuan_layout, IsFangyuan, rt1);
        IsOpenOrClose(kehu_layout, IsKehu, rt2);
        back_btn.setVisibility(View.VISIBLE);
        open_icon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (EmmApplication.isNull(cj_type.getText().toString().trim()) == false) {
                    EmmApplication.Ts("请选择成交类别");
                    return;
                }
                if (typefound == 0) {
                    if (jjlist.size() < 1) {
                        JJInfo jinfo = new JJInfo();
                        jinfo.setName("");
                        jinfo.setNumber("");
                        jjlist.add(jinfo);
                        if (jjadapter == null) {
                            setjjdate();
                        }
                        jjadapter.SetDate(jjlist);
                    } else {
                        EmmApplication.Ts("经纪人数量已达上限");
                    }
                } else {
                    if (jjlist.size() < 3) {
                        JJInfo jinfo = new JJInfo();
                        jinfo.setName("");
                        jinfo.setNumber("");
                        jjlist.add(jinfo);
                        if (jjadapter == null) {
                            setjjdate();
                        }
                        jjadapter.SetDate(jjlist);
                    } else {
                        EmmApplication.Ts("经纪人数量已达上限");
                    }
                }
            }
        });

        referenceProportion.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                double allprice = 0;
                for (int i = 0; i < jjlist.size(); i++) {
                    String str = (EmmApplication.isNull(jjlist.get(i).getNumber()) == true ? jjlist.get(i).getNumber()
                            : "0");
                    allprice += Double.valueOf(str).doubleValue();
                }
                allprice += Double.valueOf(EmmApplication.isNull(s.toString()) ? s.toString() : "0").doubleValue();
                if (allprice > 100) {
                    referenceProportion.setText(s.toString().substring(0, (s.toString().length() - 1)));
                    referenceProportion.setSelection(referenceProportion.getText().toString().trim().length());
                    EmmApplication.Ts("分佣比例总和不能大于100%");
                    return;
                }
                jjadapter.SetReferenceProportion(Double.valueOf(EmmApplication.isNull(s.toString()) ? s.toString() : "0")
                        .doubleValue());
            }
        });

        back_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        fangyuan.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DoOpenOrClose(IsFangyuan);
            }
        });
        kehu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DoKehuOpenOrClose(IsKehu);
            }
        });
        is_sure.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if ("1".equals(OpenType) || "5".equals(OpenType)) {
                    Loading.hideDialogForLoading();
                    Loading.showDialogForLoading(NewSubscribeActivity.this, "正在保存...", false, true, 100000);
                    RecordTaskUpdate record = new RecordTaskUpdate("0", 0);
                    record.execute();
                } else {
                    Loading.hideDialogForLoading();
                    Loading.showDialogForLoading(NewSubscribeActivity.this, "正在保存...", false, true, 100000);
                    RecordTaskUpdate record = new RecordTaskUpdate("0", 1);
                    record.execute();
                }
            }
        });
        reject_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("1".equals(OpenType) || "5".equals(OpenType)) {
                    Loading.showDialogForLoading(NewSubscribeActivity.this, "正在提交...", false, true, 100000);
                    RecordTaskUpdate record = new RecordTaskUpdate("1", 0);
                    record.execute();
                } else {
                    Loading.showDialogForLoading(NewSubscribeActivity.this, "正在提交...", false, true, 100000);
                    RecordTaskUpdate record = new RecordTaskUpdate("1", 1);
                    record.execute();
                }
            }
        });
        housing_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (houseDetail == null) {
                    EmmApplication.housinglist.clear();
                    EmmApplication.IsGet = true;
                    startActivity(new Intent(NewSubscribeActivity.this, HousingresourcesActivity.class));
                }
            }
        });
        adapter = new NewFromAdapter(NewSubscribeActivity.this, list);
        kehuxinxi.setAdapter(adapter);
        add.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (list.size() >= 3) {
                    EmmApplication.T("最多添加4位");
                } else {
                    NewClassKehuModel n = new NewClassKehuModel();
                    n.setNumber("" + (list.size() + 2));
                    list.add(n);
                    adapter.SetDate(list);
                }
            }
        });
        zj_type.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listname = new ArrayList<String>();
                if (DocumentType != null) {
                    for (int i = 0; i < DocumentType.size(); i++) {
                        listname.add(DocumentType.get(i).getDictionaryName());
                    }
                    setZpPoPu(listname, "证件类型", zj_type);
                } else {
                    PopuContent.poPu(NewSubscribeActivity.this, "证件类型获取失败", false, 1);
                }
            }
        });
        peDocumentNumber_view.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (null != s.toString()) {
                    if ("身份证".equals(zj_type.getText().toString().trim())) {
                        if (s.toString().length() > 18) {
                            peDocumentNumber_view.setText(s.toString().trim()
                                    .substring(0, s.toString().trim().length() - 1));
                            peDocumentNumber_view.setSelection(peDocumentNumber_view.getText().toString().trim()
                                    .length());
                        }
                    }
                }
            }
        });
        p_from_time.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                changeRGtime();
            }
        });
        rg_times.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 再次选择认购日期时，置空认购转合同到期时间
                p_from_time.setText("");
                p_from_time.setHint("未选择");
                time_ed = rg_times;
                // 调用时间选择器
                time_SelectPicPopupWindow = new Time_SelectPicPopupWindow(NewSubscribeActivity.this, keyListener, 0,
                        GetDate(rg_times));
                time_SelectPicPopupWindow.showAtLocation(title_main, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
            }
        });
        pay_type.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listname = new ArrayList<String>();
                listname.add("一次性付款");
                listname.add("分期付款");
                listname.add("商业贷款");
                listname.add("公积金贷款");
                listname.add("组合贷款");
                setZpPoPu(listname, "付款方式", pay_type);
            }
        });
        cj_type.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listname = new ArrayList<String>();
                listname.add("推荐成交");
                listname.add("单独成交");
                listname.add("共同成交");
                setZpPoPu(listname, "成交类别", cj_type);
            }
        });
        cj_type.setText("单独成交");
        cj_type.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (null != s.toString()) {
                    if ("共同成交".equals(s.toString())) {
                        typefound = 1;
                        if (null != jjlist && jjlist.size() > 0) {
                            jjadapter.SetDate(jjlist);
                        } else {
                            NewSignedActivity.JJInfo n = new JJInfo();
                            jjlist = new ArrayList<NewSignedActivity.JJInfo>();
                            n.setName(EmmApplication.getUserName());
                            n.setNumber("100");
                            n.setPid(EmmApplication.getUserId());
                            jjlist.clear();
                            jjlist.add(n);
                            if (jjadapter == null) {
                                setjjdate();
                            }
                            jjadapter.SetDate(jjlist);
                        }
                    } else {
                        typefound = 0;
                        NewSignedActivity.JJInfo n = new JJInfo();
                        if (null != jjlist && jjlist.size() > 0) {
                            n = jjlist.get(0);
                            jjlist.clear();
                            if (EmmApplication.isNull(n.getName())) {
                            } else {
                                n.setName(EmmApplication.getUserName());
                                n.setNumber("100");
                                n.setPid(EmmApplication.getUserId());
                            }
                            jjlist.add(n);
                            if (jjadapter == null) {
                                setjjdate();
                            }
                            jjadapter.SetDate(jjlist);
                        } else {
                            jjlist = new ArrayList<NewSignedActivity.JJInfo>();
                            n.setName(EmmApplication.getUserName());
                            n.setNumber("100");
                            n.setPid(EmmApplication.getUserId());
                            jjlist.clear();
                            jjlist.add(n);
                            if (jjadapter == null) {
                                setjjdate();
                            }
                            jjadapter.SetDate(jjlist);
                        }
                    }
                    if ("推荐成交".equals(s.toString())) {
                        reference_linear_layout.setVisibility(View.VISIBLE);
                    } else {
                        reference_linear_layout.setVisibility(View.GONE);
                    }
                } else {
                    typefound = 0;
                }
            }
        });

        more_referenceName.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                List<String> listname = new ArrayList<String>();
                if (null == getRecommendCustomerListHander
                        || null == getRecommendCustomerListHander.getRecommendCustomerList()) {
                    return;
                }
                for (int i = 0; i < getRecommendCustomerListHander.getRecommendCustomerList().size(); i++) {
                    listname.add(getRecommendCustomerListHander.getRecommendCustomerList().get(i).getCustomerName());
                }
                if (listname.size() <= 0) {
                    EmmApplication.Ts("当前没有可选客户");
                    return;
                } else {
                    setZpPoPu(listname, "客户", referenceName);
                }
            }
        });
        p_jjrmine.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                getConsultantList(0);
            }
        });

        depositReceivable_view.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (EmmApplication.isNull(s.toString())) {
                    if (s.toString().indexOf(".") >= 0) {
                        if (s.toString().indexOf(".", s.toString().indexOf(".") + 1) > 0) {
                            // 已重复输入
                            depositReceivable_view.setText(depositReceivable_view.getText().toString()
                                    .substring(0, depositReceivable_view.getText().toString().length() - 1));
                            depositReceivable_view.setSelection(depositReceivable_view.getText().toString().length());
                        }
                    }
                }
            }
        });

        // 增加折扣率等计算
        discountAmount_view.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (PriceType == 0) {

                } else {
                    if (EmmApplication.isNull(s.toString())) {
                        if (s.toString().indexOf(".") >= 0) {
                            if (s.toString().indexOf(".", s.toString().indexOf(".") + 1) > 0) {
                                // 已重复输入
                                discountAmount_view.setText(discountAmount_view.getText().toString()
                                        .substring(0, discountAmount_view.getText().toString().length() - 1));
                                discountAmount_view.setSelection(discountAmount_view.getText().toString().length());
                            }
                        }

                        if (EmmApplication.isNull(FrdID)) {// 不为空，已选择房源
                            discountRate_view.setText("");
                            if (Double.valueOf(discountAmount_view.getText().toString().trim()).doubleValue() > (Double
                                    .valueOf(discountTotalPrice_view.getText().toString().trim()).doubleValue()
                                    // * 10000
                            )) {
                                EmmApplication.Ts("折扣金额不能大于折前总价");
                                try {
                                    discountAmount_view.setText(""
                                            + EmmApplication.drop2(""
                                            + (Double.valueOf(discountTotalPrice_view.getText().toString()
                                            .trim()).doubleValue()
                                            // * 10000
                                    )));
                                } catch (NullPointerException e) {
                                    Log.v(TAG, "折扣金额大于折前总价处重置展示异常");
                                }
                                return;
                            }
                            double str = (1 - (Double.valueOf(discountAmount_view.getText().toString().trim())
                                    .doubleValue() / (Double.valueOf(discountTotalPrice_view.getText().toString()
                                    .trim()).doubleValue()
                                    // * 10000
                            ))) * 100;

                            String numb = EmmApplication.drop2("" + str);
                            discountRate_view.setText(numb);
                            number1.setText(numb + "%");

                            if (Double.valueOf(numb).doubleValue() < Double.valueOf(Hdnumber).doubleValue()) {
                                Log.v("警告", "折扣比例已低于浮动值比例" + numb + "%");
                                is_code2.setVisibility(View.VISIBLE);
                                is_code1.setVisibility(View.VISIBLE);
                                line_type_for_code.setVisibility(View.VISIBLE);
                                IsDis = true;
                            } else {
                                is_code2.setVisibility(View.GONE);
                                is_code1.setVisibility(View.GONE);
                                line_type_for_code.setVisibility(View.GONE);
                                IsDis = false;
                            }

                            double discountTotalPrice_ = (Double.valueOf(discountTotalPrice_view.getText().toString()
                                    .trim()).doubleValue()
                                    // * 10000
                            );
                            contractAmount_view.setText(EmmApplication.drop2(""
                                            + ((discountTotalPrice_ - Double.valueOf(
                                    discountAmount_view.getText().toString().trim()).doubleValue()))
                                    // / 10000
                            )
                                    + "");

                            contractPrice_view.setText(EmmApplication.drop2(""
                                    + ((Double.valueOf(contractAmount_view.getText().toString().trim()).doubleValue()
                                    // * 10000
                            ) / Double.valueOf(valuation_area.getText().toString().trim()).doubleValue())));

                        } else {
                            EmmApplication.T("请先选择房源");
                            EmmApplication.disKey(NewSubscribeActivity.this);
                            discountAmount_view.setText("");
                        }
                    }
                }
            }
        });

        discountAmount_all_view.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (EmmApplication.isNull(s.toString())) {
                    if (s.toString().indexOf(".") >= 0) {
                        if (s.toString().indexOf(".", s.toString().indexOf(".") + 1) > 0) {
                            // 已重复输入
                            discountAmount_all_view.setText(discountAmount_all_view.getText().toString()
                                    .substring(0, discountAmount_all_view.getText().toString().length() - 1));
                            discountAmount_all_view.setSelection(discountAmount_all_view.getText().toString().length());
                        }
                    }
                    if (EmmApplication.isNull(FrdID)) {// 不为空，已选择房源

                        discountAmount_view.setText(""
                                + ((Double.valueOf(discountTotalPrice_view.getText().toString().trim()).doubleValue()
                                // * 10000
                        ) - Double.valueOf(discountAmount_all_view.getText().toString().trim()).doubleValue()));
                        discountRate_view.setText(EmmApplication.drop2(""
                                + (Double.valueOf(discountAmount_all_view.getText().toString().trim()).doubleValue()
                                / (Double.valueOf(discountTotalPrice_view.getText().toString().trim())
                                .doubleValue()
                                // * 10000
                        ) * 100)));
                        number1.setText(discountAmount_view.getText().toString() + "元");
                        Log.v(TAG, "1:"
                                + Double.valueOf(discountAmount_all_view.getText().toString().trim()).doubleValue());
                        Log.v(TAG, "2:" + Double.valueOf(Hdnumber).doubleValue());
                        if (Double.valueOf(discountAmount_all_view.getText().toString().trim()).doubleValue() < Double
                                .valueOf(Hdnumber).doubleValue()) {
                            Log.v("警告", "折扣比例已低于浮动值比例" + Hdnumber);
                            is_code2.setVisibility(View.GONE);
                            is_code1.setVisibility(View.GONE);
                            line_type_for_code.setVisibility(View.GONE);
                            IsDis = true;
                        } else {
                            is_code2.setVisibility(View.GONE);
                            is_code1.setVisibility(View.GONE);
                            line_type_for_code.setVisibility(View.GONE);
                            IsDis = false;
                        }
                        if (Double.valueOf(discountAmount_all_view.getText().toString().trim()).doubleValue() <= 0) {
                            contractAmount_view.setText(discountTotalPrice_view.getText().toString());
                            contractPrice_view.setText(folding_front_unit_price.getText().toString());
                        } else {
                            contractAmount_view.setText(EmmApplication.drop2(""
                                    + (Double.valueOf(discountAmount_all_view.getText().toString().trim())
                                    .doubleValue()
                                    // / 10000
                            )));

                            contractPrice_view.setText(EmmApplication.drop2(""
                                    + ((Double.valueOf(contractAmount_view.getText().toString().trim()).doubleValue()
                                    // * 10000
                            ) / Double.valueOf(valuation_area.getText().toString().trim()).doubleValue())));
                        }
                    } else {
                        EmmApplication.T("请先选择房源");
                        EmmApplication.disKey(NewSubscribeActivity.this);
                        discountAmount_all_view.setText("");
                    }
                } else {
                    discountRate_view.setText("0");
                    discountAmount_view.setText("0");
                    number1.setText("0%");
                    contractAmount_view.setText(discountTotalPrice_view.getText().toString().trim());
                    contractPrice_view.setText(folding_front_unit_price.getText().toString().trim());
                }
            }
        });

        SetDate();
        padapter = new PhoneSelectAdapter(NewSubscribeActivity.this, ap, 1);
        grid_phone.setAdapter(padapter);
        grid_phone.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if ("1".equals(ap.get(position).getType())) {
                    ViewPagerActivity.postion = position;
                    ViewPagerActivity.sDrawables.clear();
                    for (int u = 0; u < ap.size(); u++) {
                        if ("1".equals(ap.get(u).getType())) {
                            if ("1".equals(ap.get(u).getIsnet())) {
                                ViewPagerActivity.sDrawables.add("file://" + ap.get(u).getPath());
                            } else {
                                ViewPagerActivity.sDrawables.add(ap.get(u).getPath());
                            }
                        }
                    }
                    Intent intent = new Intent(NewSubscribeActivity.this, ViewPagerActivity.class);
                    intent.putExtra("IsOpenDelete", 0);
                    startActivity(intent);
                }
            }
        });

    }

    /**
     * <p>
     * <b>Title：</b> 获取输入框的时间数据
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param view
     * @return
     * @author tangxin
     * @date 2016年12月27日 上午11:13:58
     */
    private Date GetDate(EditText view) {
        if (null != view.getText().toString().trim() && !"".equals(view.getText().toString().trim())
                && !"null".equals(view.getText().toString().trim())) {
            DateFormat fmt = new SimpleDateFormat("yyyy年MM月dd日");
            Date date = null;
            try {
                date = fmt.parse(view.getText().toString().trim());
            } catch (ParseException e) {
                date = new Date(System.currentTimeMillis());
                e.printStackTrace();
            }
            return date;
        } else {
            return new Date(System.currentTimeMillis());
        }
    }

    /**
     * <p>
     * <b>Title：</b> 添加默认数据
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:52:00
     */
    private void SetDate() {
        ap = new ArrayList<AddpirModel>();
        AddpirModel a = new AddpirModel();
        a.setIsnet("1");
        a.setType("2");
        a.setPath("");
        ap.add(a);
    }

    /**
     * <p>
     * <b>Title：</b> 判断各展开状况
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param view
     * @param bl
     * @param view2
     * @author tangxin
     * @date 2016年12月7日 下午4:00:40
     */
    private void IsOpenOrClose(View view, boolean bl, ImageView view2) {
        if (bl) {
            view.setVisibility(View.VISIBLE);
            view2.setImageResource(R.drawable.j_bottom);
        } else {
            view.setVisibility(View.GONE);
            view2.setImageResource(R.drawable.j_top);
        }
    }

    /**
     * <p>
     * <b>Title：</b> 判断操作中的房源模块的展开状况
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param bl
     * @author tangxin
     * @date 2016年12月7日 下午4:00:47
     */
    private void DoOpenOrClose(boolean bl) {
        if (!bl) {
            IsFangyuan = true;
            fangyuan_layout.setVisibility(View.VISIBLE);
            rt1.setImageResource(R.drawable.j_bottom);
        } else {
            IsFangyuan = false;
            fangyuan_layout.setVisibility(View.GONE);
            rt1.setImageResource(R.drawable.j_top);
        }
    }

    /**
     * <p>
     * <b>Title：</b> 判断操作中的客户信息模块的展开状况
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param bl
     * @author tangxin
     * @date 2016年12月7日 下午4:00:57
     */
    private void DoKehuOpenOrClose(boolean bl) {
        if (!bl) {
            IsKehu = true;
            kehu_layout.setVisibility(View.VISIBLE);
            rt2.setImageResource(R.drawable.j_bottom);
        } else {
            IsKehu = false;
            kehu_layout.setVisibility(View.GONE);
            rt2.setImageResource(R.drawable.j_top);
        }
    }

    /**
     * 0 底价；1 折扣 默认底价
     */
    private int PriceType = 0;

    @Override
    protected void onResume() {
        super.onResume();
        BaseActivity.activity = this;
        if (EmmApplication.IsGet) {
            EmmApplication.IsGet = false;

            if (EmmApplication.housinglist != null && EmmApplication.housinglist.size() > 0) {

                String floorType = EmmApplication.housinglist.get(0).getFloorType();
                if (EmmApplication.isNull(floorType)) {
                    PriceType = Integer.valueOf(floorType).intValue();
                } else {
                    PriceType = 0;
                }

                housing_btn.setText(EmmApplication.housinglist.get(0).getRoomName());
                FrdID = EmmApplication.isNull(EmmApplication.housinglist.get(0).getRoomId()) ? EmmApplication.housinglist.get(0)
                        .getRoomId() : "";
                valuation_area
                        .setText(EmmApplication.isNull(EmmApplication.room.getCalculateArea()) == true ? EmmApplication.room
                                .getCalculateArea() : "0");
                folding_front_unit_price
                        .setText(EmmApplication.isNull(EmmApplication.room.getDiscountPrice()) == true ? EmmApplication.room
                                .getDiscountPrice() : "0");
                discountTotalPrice_view
                        .setText(EmmApplication.isNull(EmmApplication.room.getDiscountTotalPrice()) == true ? EmmApplication.room
                                .getDiscountTotalPrice() : "0");
                if (PriceType == 1) {
                    discountAmount_all_view_linear.setVisibility(View.GONE);
                    Hdnumber = EmmApplication.isNull(EmmApplication.housinglist.get(0).getDiscountRate()) ? EmmApplication.housinglist
                            .get(0).getDiscountRate() : "0";
                    Hdprice = EmmApplication.isNull(EmmApplication.housinglist.get(0).getDiscountAmount()) ? EmmApplication.housinglist
                            .get(0).getDiscountAmount() : "";
                    number2.setText(Hdnumber + "%");
                    // 折扣不默认为空，需要根据房源带出显示
                    // if (EmmApplication.IsNewSelect) {
                    // EmmApplication.IsNewSelect = false;
                    // discountAmount_view.setText("");
                    // } else {
                    discountAmount_view.setText(EmmApplication.drop2(Hdprice));
                    // }

                    discountAmount_view.setEnabled(true);
                } else {
                    discountAmount_view.setEnabled(false);
                    discountAmount_all_view_linear.setVisibility(View.VISIBLE);
                    Hdnumber = EmmApplication.isNull(EmmApplication.housinglist.get(0).getDiscountRate()) ? EmmApplication.housinglist
                            .get(0).getDiscountRate() : "0";
                    number2.setText(Hdnumber + "元");
                    if (EmmApplication.IsNewSelect) {
                        EmmApplication.IsNewSelect = false;
                        discountAmount_all_view.setText("");
                    } else {
                        if (EmmApplication.isNull(EmmApplication.room.getDiscountTotalPrice())
                                && EmmApplication.isNull(EmmApplication.room.getDiscountAmount())) {
                            double number = (Double.valueOf(EmmApplication.room.getDiscountTotalPrice()).doubleValue()
                                    // * 10000
                            )
                                    - Double.valueOf(EmmApplication.room.getDiscountAmount()).doubleValue();
                            discountAmount_all_view.setText(EmmApplication.drop2("" + number));
                        } else {
                            discountAmount_all_view.setText("");
                        }
                    }
                }
            }
        }

        SetImage();// 在ImageChooseActivity界面选定图片后返回该界面时给图片附件的gridview填充数据

        IntentFilter filterr = new IntentFilter();
        filterr.addAction("open_Image_popu");
        registerReceiver(mBroadcastReceiver, filterr);
    }

    private void SetImage() {
        // 0不变 1删除
        if (null != EmmApplication.pir || EmmApplication.pir.size() > 0) {
            if (null != ap) {
                // ap.clear();
            } else {
                ap = new ArrayList<AddpirModel>();
            }
            if (EmmApplication.IsCreate) {// 是否新建，需要创建一个按钮
                EmmApplication.IsCreate = false;
                ap.clear();
                AddpirModel a = new AddpirModel();
                a.setIsnet("1");
                a.setType("2");
                a.setPath("");
                ap.add(a);
            }
            for (int i = 0; i < EmmApplication.pir.size(); i++) {
                int y = 0;
                for (int n = 0; n < ap.size(); n++) {
                    if (EmmApplication.pir.get(i).sourcePath.equals(ap.get(n).getPath())) {
                        y++;
                    }
                }
                if (y > 0) {
                    Log.v(TAG, "已存在，不添加");
                } else {
                    AddpirModel a = new AddpirModel();
                    a.setIsnet(EmmApplication.pir.get(i).type);
                    a.setType("1");
                    a.setPath(EmmApplication.pir.get(i).sourcePath);
                    ap.add(0, a);
                }
            }
            padapter.SetDate(ap);
        }
    }

    /**
     * 广播监听方法 当点击添加图片按钮时，接收到广播，弹出popupwindow
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals("open_Image_popu")) {
                popu();
            }
        }
    };

    @Override
    protected void onDestroy() {
        unregisterReceiver(mBroadcastReceiver);
        EmmApplication.IsLoadingFromList = false;// 解除限制
        super.onDestroy();
        EmmApplication.pir.clear();
    }

    /**
     * <p>
     * <b>Title：</b> 选项框
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param listname
     * @param title
     * @param ed
     * @author tangxin
     * @date 2016年12月7日 下午4:01:07
     */
    @SuppressLint("WrongConstant")
    public void setZpPoPu(final List<String> listname, String title, final EditText ed) {
        view = LayoutInflater.from(NewSubscribeActivity.this).inflate(R.layout.popu_zp, null);
        popu = new PopupWindow(view, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
        popu.setFocusable(true);
        popu.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popu.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popu.showAtLocation(view, Gravity.TOP, 0, 0);
        popu.showAsDropDown(view, 0, 0);
        popu.setFocusable(true);
        popu.setOutsideTouchable(true);
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    popu.dismiss();
                    EmmApplication.setLog(NewSubscribeActivity.this);
                }
                return false;
            }
        });
        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                popu.dismiss();
                EmmApplication.setLog(NewSubscribeActivity.this);
            }
        });

        PickerView select_pick = (PickerView) view.findViewById(R.id.select_pick);

        selectName = listname.get(0);

        TextView shuerbtn = (TextView) view.findViewById(R.id.shuerbtn);
        RelativeLayout relative_all = (RelativeLayout) view.findViewById(R.id.relative_all);

        ImageView dis_btn = (ImageView) view.findViewById(R.id.dis_btn);
        dis_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu.dismiss();
                EmmApplication.setLog(NewSubscribeActivity.this);
            }
        });
        TextView title_select = (TextView) view.findViewById(R.id.title_select);

        title_select.setText(title);

        select_pick.setData(listname);
        select_pick.setOnSelectListener(new onSelectListener() {
            @Override
            public void onSelect(String text, int id) {
                selectName = text;
                SelectID = id;
            }
        });
        select_pick.setSelected(0);
        shuerbtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 确定
                popu.dismiss();
                EmmApplication.setLog(NewSubscribeActivity.this);
                ed.setText(selectName);
            }
        });
        relative_all.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }

    OnClickListener keyListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.imageView1:
                    time_SelectPicPopupWindow.dismiss();
                    time_SelectPicPopupWindow.Aprils.clear();
                    time_SelectPicPopupWindow.Years.clear();
                    time_SelectPicPopupWindow.Days.clear();

                    SimpleDateFormat formats = new SimpleDateFormat("yyyy年MM月dd日");
                    Calendar c = Calendar.getInstance();
                    try {
                        c.setTime(formats.parse(time_SelectPicPopupWindow.getLanguage()
                                + time_SelectPicPopupWindow.getType_One() + time_SelectPicPopupWindow.getType()));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                    Date endDate = c.getTime();
                    String str = formats.format(endDate);
                    Log.w(TAG, "str:" + str);
                    time_ed.setText(str);
                    break;
                default:
                    break;
            }
        }
    };

    OnClickListener keyListener2 = new OnClickListener() {
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.imageView1:
                    if (TextUtils.isEmpty(popupWindow_Test.getType()) || TextUtils.isEmpty(popupWindow_Test.getType_One())) {
                        EmmApplication.T("亲，您选择的地址有误，请重新选择");
                    } else {
                        addr_ed.setText(popupWindow_Test.getLanguage() + popupWindow_Test.getType()
                                + popupWindow_Test.getType_One());
                        EmmApplication.areaIds = popupWindow_Test.getareaId_one() + "|" + popupWindow_Test.getareaId_two()
                                + "|" + popupWindow_Test.getareaId_three();
                    }
                    Log.w("areaIds:", EmmApplication.areaIds);
                    popupWindow_Test.dismiss();
                    break;
                default:
                    break;
            }
        }

        ;
    };

    /**
     * 新增认购接口
     */
    AddSubscribe addSubscribe;

    /**
     * <p>
     * <b>Title：</b> 新增认购接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param auditStatus
     * @param type
     * @author tangxin
     * @date 2016年12月7日 下午4:02:40
     */
    private void AddSubscribe(ArrayList<ImageListInfo> contentList_, String auditStatus, int type) {

        Map<String, Object> map = new HashMap<String, Object>();
        if (type == 0) {
            EmmApplication.updateUrl("addSubscribe");
        } else {
            EmmApplication.updateUrl("editSubscribe");
            map.put("subscribeId", subscribeId);
        }
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("customerId", customerId);
        map.put("subscribeCode", rengou_code.getText().toString().trim());// 认购编号
        map.put("payDepositId", payDepositId);// payDepositId 认筹ID
        map.put("payDepositCode", payDepositCode);// payDepositCode 认筹编号
        map.put("payDepositMoney", payDepositMoney);// payDepositMoney 认筹金
        map.put("projectId", EmmApplication.getProjectID());

        if (0 == PriceType) {
            map.put("discountAfterAmount", discountAmount_all_view.getText().toString().trim());
        }

        map.put("auditStatus", auditStatus);// 0代表保存，1，代表提交审核

        // 图片附件
        map.put("imageList", contentList_);

        if (EmmApplication.isNull(FrdID)) {
            map.put("roomId", FrdID);// roomId 认购房源
        } else {
            handler.sendEmptyMessage(71);
            // PopuContent.tips(NewSubscribeActivity.this, "请选择认购房源", false, 1);
            return;
        }

        map.put("calculateArea", valuation_area.getText().toString().trim());// calculateArea
        // 计价面积

        map.put("discountPrice", folding_front_unit_price.getText().toString().trim());// discountPrice
        // 折前单价

        map.put("discountTotalPrice", discountTotalPrice_view.getText().toString().trim());// discountTotalPrice

        if (EmmApplication.isNull(customerName_view.getText().toString().trim())) {
            map.put("memberName", customerName_view.getText().toString().trim());
        } else {
            handler.sendEmptyMessage(72);
            // PopuContent.tips(NewSubscribeActivity.this, "请输入姓名", false, 1);
            return;
        }

        // 证件类型：1、身份证；2、护照；3、营业执照；4、户口薄；5、军官证；
        // 6、临时身份证；7、港澳台同胞来往通行证；8、边民出入境通行证；
        // 9、外国人永久居留证；10、警官证；11、士兵证；12、其他
        Log.v(TAG, "身份证" + zj_type.getText().toString().trim());
        if (EmmApplication.isNull(zj_type.getText().toString().trim())) {

            if (null != DocumentType && DocumentType.size() > 0) {
                for (int i = 0; i < DocumentType.size(); i++) {
                    if (zj_type.getText().toString().trim().equals(DocumentType.get(i).getDictionaryName())) {
                        map.put("documentType", DocumentType.get(i).getDictionaryId());
                    }
                }
            } else {
                handler.sendEmptyMessage(73);
                return;
            }
        } else {
            // EmmApplication.T("请选择证件类型");
            // PopuContent.tips(NewSubscribeActivity.this, "请选择证件类型", false, 1);
            // return;
        }

        // 证件号码
        if (EmmApplication.isNull(peDocumentNumber_view.getText().toString().trim())) {
            if ("身份证".equals(zj_type.getText().toString().trim())) {
                if (EmmApplication.isTrueCode(peDocumentNumber_view.getText().toString().trim())) {
                    map.put("documentNumber", peDocumentNumber_view.getText().toString().trim());
                } else {
                    handler.sendEmptyMessage(74);
                    return;
                }
            } else {
                map.put("documentNumber", peDocumentNumber_view.getText().toString().trim());
            }
        } else {
             handler.sendEmptyMessage(76);
             return;
        }
        // 手机号码
        if (EmmApplication.isNull(customerPhone_view.getText().toString().trim())) {
            map.put("mobile", customerPhone_view.getText().toString().trim());
        } else {
            handler.sendEmptyMessage(75);
            // PopuContent.tips(NewSubscribeActivity.this, "请输入手机号码", false, 1);
            return;
        }

        // 邮寄地址
        if (EmmApplication.isNull(select_address.getText().toString().trim())) {
            map.put("mailPost", select_address.getText().toString().trim());
        }

        // 邮编
        if (EmmApplication.isNull(pePostcode_view.getText().toString().trim())) {
            map.put("postcode", pePostcode_view.getText().toString().trim());
        } else {
            // EmmApplication.T("请填写邮编");
            // PopuContent.tips(NewSubscribeActivity.this, "请填写邮编", false, 1);
            // return;
        }

        map.put("type", "2");

        map.put("category", "2");

        ArrayList<CustomerFamilyListInfo> customerFamilyList = new ArrayList<CustomerFamilyListInfo>();

        for (int i = 0; i < list.size(); i++) {
            CustomerFamilyListInfo f = new CustomerFamilyListInfo();
            if (!EmmApplication.isNull(list.get(i).getName())) {
                handler.sendEmptyMessage(77);
                // PopuContent.tips(NewSubscribeActivity.this, "第" + (i + 1) +
                // "位成员名称未填", false, 1);
                return;
            }
            if (!EmmApplication.isNull(list.get(i).getType())) {
                handler.sendEmptyMessage(78);
                // PopuContent.tips(NewSubscribeActivity.this, "第" + (i + 1) +
                // "位成员证件类型未选", false, 1);
                return;
            }
            if (!EmmApplication.isNull(list.get(i).getCode())) {
                handler.sendEmptyMessage(79);
                // PopuContent.tips(NewSubscribeActivity.this, "第" + (i + 1) +
                // "位成员证件号未填", false, 1);
                return;
            }
            f.setMemberName(list.get(i).getName());
            f.setDocumentNumber(list.get(i).getCode());
            String stn = list.get(i).getType();
            if (null != DocumentType && DocumentType.size() > 0) {
                for (int y = 0; y < DocumentType.size(); y++) {
                    if (stn.equals(DocumentType.get(y).getDictionaryName())) {
                        f.setDocumentType(DocumentType.get(y).getDictionaryId());
                    }
                }
            } else {
                handler.sendEmptyMessage(80);
                return;
            }
            customerFamilyList.add(f);
        }
        map.put("customerFamilyList", customerFamilyList);

        map.put("discountAmount", discountAmount_view.getText().toString().trim());// discountAmount
        // 折扣金额
        map.put("discountRate", discountRate_view.getText().toString().trim());// discountRate
        // 折扣比例
        map.put("discountNote", discountNote_view.getText().toString().trim());// discountNote
        // 折扣说明
        map.put("contractPrice", contractPrice_view.getText().toString().trim());// contractPrice
        // 签约单价
        map.put("contractAmount", contractAmount_view.getText().toString().trim());// contractAmount
        // 合同金额

        if (EmmApplication.isNull(depositReceivable_view.getText().toString().trim())) {// depositReceivable
            // 应收定金
            map.put("depositReceivable", depositReceivable_view.getText().toString().trim());
        } else {
            handler.sendEmptyMessage(81);
            // PopuContent.tips(NewSubscribeActivity.this, "应收定金为空", false, 1);
            return;
        }

        // 认购转合同到期时间
        if (EmmApplication.isNull(p_from_time.getText().toString().trim())) {
            map.put("dueTime", EmmApplication.replaceTime(p_from_time.getText().toString().trim()));// dueTime
        } else {
            handler.sendEmptyMessage(93);
            return;
        }

        if ("一次性付款".equals(pay_type.getText().toString().trim())) {// paymentMethod
            map.put("paymentMethod", "1");
        } else if ("分期付款".equals(pay_type.getText().toString().trim())) {
            map.put("paymentMethod", "2");
        } else if ("商业贷款".equals(pay_type.getText().toString().trim())
                || "商业按揭".equals(pay_type.getText().toString().trim())) {
            map.put("paymentMethod", "3");
        } else if ("公积金贷款".equals(pay_type.getText().toString().trim())
                || "公积金按揭".equals(pay_type.getText().toString().trim())) {
            map.put("paymentMethod", "4");
        } else if ("组合贷款".equals(pay_type.getText().toString().trim())) {
            map.put("paymentMethod", "5");
        } else {
            // EmmApplication.T("请选择付款方式");
            // PopuContent.tips(NewSubscribeActivity.this, "请选择付款方式", false, 1);
            // return;
        }

        if (EmmApplication.isNull(cj_type.getText().toString())) {
            if ("推荐成交".equals(cj_type.getText().toString().trim())) {// dealCategory
                map.put("dealCategory", "1");
                String referenceName_id = "";
                for (int i = 0; i < getRecommendCustomerListHander.getRecommendCustomerList().size(); i++) {
                    if (referenceName.getText().toString()
                            .equals(getRecommendCustomerListHander.getRecommendCustomerList().get(i).getCustomerName())) {
                        referenceName_id = getRecommendCustomerListHander.getRecommendCustomerList().get(i)
                                .getCustomerId();
                    }
                }
                map.put("referenceId", referenceName_id);
                if (EmmApplication.isNull(referenceName.getText().toString().trim())) {
                    map.put("referenceName", referenceName.getText().toString().trim());
                } else {
                    handler.sendEmptyMessage(82);
                    // PopuContent.tips(NewSubscribeActivity.this, "请输入客户",
                    // false, 1);
                    return;
                }

                if (EmmApplication.isNull(referenceProportion.getText().toString().trim())) {
                    map.put("referenceProportion", referenceProportion.getText().toString().trim());
                } else {
                    handler.sendEmptyMessage(83);
                    // PopuContent.tips(NewSubscribeActivity.this, "请输入客户分佣比例",
                    // false, 1);
                    return;
                }

            } else if ("单独成交".equals(cj_type.getText().toString().trim())) {
                map.put("dealCategory", "2");
            } else if ("共同成交".equals(cj_type.getText().toString().trim())) {
                map.put("dealCategory", "3");
            } else {
                // EmmApplication.T("请选择成交类型");
                // PopuContent.tips(NewSubscribeActivity.this, "请选择成交类型", false,
                // 1);
                // return;
            }
        } else {
            // EmmApplication.Ts("请选择成交类型");
            // PopuContent.tips(NewSubscribeActivity.this, "请选择成交类型", false, 1);
            // return;
        }

        ArrayList<dealCategoryList> dealcategorylist = new ArrayList<NewSignedActivity.dealCategoryList>();

        for (int p = 0; p < jjlist.size(); p++) {
            dealCategoryList d = new dealCategoryList();
            if (EmmApplication.isNull(jjlist.get(p).getNumber()) == false) {
                handler.sendEmptyMessage(84);
                // PopuContent.tips(NewSubscribeActivity.this, "请填写经纪人信息",
                // false, 1);
                return;
            }
            d.setProportionCommission(jjlist.get(p).getNumber());
            if (EmmApplication.isNull(jjlist.get(p).getPid()) == false) {
                handler.sendEmptyMessage(85);
                // PopuContent.tips(NewSubscribeActivity.this, "请填写经纪人信息",
                // false, 1);
                return;
            }
            d.setRelationAgentId(jjlist.get(p).getPid());
            dealcategorylist.add(d);
        }

        if (EmmApplication.isNull(cj_type.getText().toString().trim())) {
            if (dealcategorylist.size() <= 0) {
                handler.sendEmptyMessage(86);
                // PopuContent.tips(NewSubscribeActivity.this, "请添加经纪人信息",
                // false, 1);
                return;
            }
            if ("共同成交".equals(cj_type.getText().toString().trim())) {
                if (dealcategorylist.size() < 2) {
                    handler.sendEmptyMessage(87);
                    // PopuContent.tips(NewSubscribeActivity.this,
                    // "分佣至少需要两名经纪人", false, 1);
                    return;
                }
                double allnumber = 0;
                for (int i = 0; i < dealcategorylist.size(); i++) {
                    allnumber += Double.valueOf(dealcategorylist.get(i).getProportionCommission()).doubleValue();
                }
                if (allnumber < 100) {
                    handler.sendEmptyMessage(109);
                    return;
                }

            }
            if ("推荐成交".equals(cj_type.getText().toString().trim())
                    && Double.valueOf(dealcategorylist.get(0).getProportionCommission()).doubleValue() < 100) {
                handler.sendEmptyMessage(109);
                return;
            }
            if ("单独成交".equals(cj_type.getText().toString().trim())
                    && Double.valueOf(dealcategorylist.get(0).getProportionCommission()).doubleValue() < 100) {
                handler.sendEmptyMessage(109);
                return;
            }
            map.put("dealCategoryList", dealcategorylist);
        }

        if (EmmApplication.isNull(rg_times.getText().toString().trim())) {
            map.put("subscribeDate", EmmApplication.replaceTime(rg_times.getText().toString().trim()));// subscribeDate
        } else {
            handler.sendEmptyMessage(88);
            // PopuContent.tips(NewSubscribeActivity.this, "请选择认购日期", false, 1);
            return;
        }
        // 认购日期
        map.put("remark", remark_view.getText().toString().trim());// remark
        if ("1".equals("" + PriceType)) {
            if (IsDis) {
                if (EmmApplication.isNull(youhui_view.getText().toString().trim())) {
                    // EmmApplication.T("优惠说明");
                    map.put("preferentialReasons", youhui_view.getText().toString().trim());
                } else {
                    handler.sendEmptyMessage(89);
                    // PopuContent.tips(NewSubscribeActivity.this, "请输入优惠说明",
                    // false, 1);
                    return;
                }
            }
        }

        map.put("floorType", PriceType);// 0 底价；1 折扣 默认底价
        if (0 == PriceType) {
            if (IsDis && EmmApplication.isNull(discountAmount_all_view.getText().toString().trim())) {// 需要折扣审批
                map.put("discountApproval", "1");
            } else {
                map.put("discountApproval", "0");
            }
        } else {
            if (IsDis && EmmApplication.isNull(discountAmount_view.getText().toString().trim())) {// 需要折扣审批
                map.put("discountApproval", "1");
            } else {
                map.put("discountApproval", "0");
            }
        }

        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("addSubscribe-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                handler.sendEmptyMessage(91);
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                handler.sendEmptyMessage(91);
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                handler.sendEmptyMessage(90);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }

                handler.sendEmptyMessage(91);

                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                addSubscribe = JSONObject.parseObject(resData.toString(), AddSubscribe.class);

                if ("1".equals(addSubscribe.getResult())) {
                    Log.v("获取成功", "");

                    finish();
                    // 发送广播，告知刷新界面
                    if ("1".equals(OpenType)) {
                        handler.sendEmptyMessage(11);
                    } else {
                        handler.sendEmptyMessage(22);
                    }
                } else {
                    handler.sendEmptyMessage(92);
                    Log.v("获取失败", "errorCode:" + addSubscribe.getErrorCode().toString() + "errorMsg:"
                            + addSubscribe.getErrorMsg().toString());
                }
            }
        });
    }

    @SuppressLint("HandlerLeak")
    Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 11) {
                EmmApplication.T("新增认购成功");
                sendBroadcast(new Intent(EmmApplication.NEW_ON_CREATE_FROM));
                sendBroadcast(new Intent(EmmApplication.NEW_ON_CREATE_FROM_LIST));
                EmmApplication.IS_RELOAD_DETAILS = true;
            }
            if (msg.what == 22) {
                EmmApplication.T("修改认购成功");
                sendBroadcast(new Intent(EmmApplication.NEW_ON_CREATE_FROM));
                sendBroadcast(new Intent(EmmApplication.NEW_ON_CS_UB_SC_RI_DETAILS));
                EmmApplication.IsReload = 3;
            }

            if (msg.what == 55) {
                is_sure.setEnabled(true);
                reject_btn.setEnabled(true);
            }
            if (msg.what == 66) {
                is_sure.setEnabled(false);
                reject_btn.setEnabled(false);
            }

            if (msg.what == 71) {
                EmmApplication.T("请选择认购房源");
                disloading();
            } else if (msg.what == 72) {
                EmmApplication.T("请输入姓名");
                disloading();
            } else if (msg.what == 73) {
                PopuContent.poPu(NewSubscribeActivity.this, "证件类型数据获取失败", false, 0);
                disloading();
            } else if (msg.what == 74) {
                EmmApplication.T("请填写正确的身份证号码");
                disloading();
            } else if (msg.what == 75) {
                EmmApplication.T("请输入手机号码");
                disloading();
            } else if (msg.what == 76) {
                EmmApplication.T("请选择证件类型");
                disloading();
            } else if (msg.what == 77) {
                EmmApplication.T("存在家庭成员名称未填");
                disloading();
            } else if (msg.what == 78) {
                EmmApplication.Ts("存在家庭成员证件类型未选");
                disloading();
            } else if (msg.what == 79) {
                EmmApplication.Ts("存在家庭成员证件号未填");
                disloading();
            } else if (msg.what == 80) {
                PopuContent.poPu(NewSubscribeActivity.this, "证件类型数据获取失败", false, 0);
                disloading();
            } else if (msg.what == 81) {
                EmmApplication.T("应收定金为空");
                disloading();
            } else if (msg.what == 82) {
                EmmApplication.Ts("请输入客户");
                disloading();
            } else if (msg.what == 83) {
                EmmApplication.Ts("请输入客户分佣比例");
                disloading();
            } else if (msg.what == 84) {
                EmmApplication.T("请填写经纪人信息");
                disloading();
            } else if (msg.what == 85) {
                EmmApplication.T("请填写经纪人信息");
                disloading();
            } else if (msg.what == 86) {
                EmmApplication.T("请添加经纪人信息");
                disloading();
            } else if (msg.what == 87) {
                EmmApplication.T("分佣至少需要两名经纪人");
                disloading();
            } else if (msg.what == 88) {
                EmmApplication.Ts("请选择认购日期");
                disloading();
            } else if (msg.what == 89) {
                EmmApplication.T("请输入优惠说明");
                disloading();
            } else if (msg.what == 90) {
                is_sure.setEnabled(false);
                reject_btn.setEnabled(false);
            } else if (msg.what == 91) {
                is_sure.setEnabled(true);
                reject_btn.setEnabled(true);
                disloading();
            } else if (msg.what == 92) {
                if (null != addSubscribe.getErrorMsg()) {
                    PopuContent.poPu(NewSubscribeActivity.this, addSubscribe.getErrorMsg(), false, 1);
                }
            } else if (msg.what == 93) {
                EmmApplication.T("认购转合同到期时间为空");
                disloading();
            } else if (msg.what == 109) {
                EmmApplication.T("分拥比例不等于100%，请重新输入");
                disloading();
            }
        }

        ;
    };

    private void disloading() {
        Loading.hideDialogForLoading();
    }

    /**
     * 查询置业顾问列表数据源
     */
    GetConsultantList getconsultan;

    /**
     * 选择经纪人下标,默认-1为自己
     */
    private int agentId = -1;

    /**
     * <p>
     * <b>Title：</b> 查询置业顾问列表
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param type
     * @author tangxin
     * @date 2016年12月7日 下午4:05:04
     */
    private void getConsultantList(final int type) {
        EmmApplication.updateUrl("getConsultantList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("projectId", EmmApplication.getProjectID());
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getConsultantList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
                getRecommendCustomerListHander(type);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.hideDialogForLoading();
                Loading.showDialogForLoading(NewSubscribeActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("置业顾问content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }
                getRecommendCustomerListHander(type);
                getconsultan = JSONObject.parseObject(resData.toString(), GetConsultantList.class);
                if ("1".equals(getconsultan.getResult())) {
                    Log.v("获取成功", "");
                    if (getconsultan != null && getconsultan.getConsultantList() != null) {
                        if ("单独成交".equals(cj_type.getText().toString().trim())) {
                            setjjdate();
                        }
                    } else {
                        EmmApplication.T("当前没有经纪人");
                    }
                } else {
                    EmmApplication.T(getconsultan.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + getconsultan.getErrorCode().toString() + "errorMsg:"
                                + getconsultan.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("查询置业顾问", "错误信息获取空指针异常");
                    }
                }
            }
        });
    }

    GetRecommendCustomerListHander getRecommendCustomerListHander;

    private void getRecommendCustomerListHander(final int type) {
        EmmApplication.updateUrl("getRecommendCustomerListHander");
        Map<String, String> map = new HashMap<String, String>();
        map.put("userId", EmmApplication.getUserId());
        map.put("resourcesCode", "menu_0006_0001");
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("projectId", EmmApplication.getProjectID());
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getRecommendCustomerListHander-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.hideDialogForLoading();
                Loading.showDialogForLoading(NewSubscribeActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("置业顾问content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }
                setjjdate();
                if (type == 7) {
                    try {
                        SetDataView();
                    } catch (NullPointerException e) {
                        Log.v(TAG, "数据填充空指针：" + e.getMessage());
                    }
                }
                getRecommendCustomerListHander = JSONObject.parseObject(resData.toString(),
                        GetRecommendCustomerListHander.class);
                if ("1".equals(getRecommendCustomerListHander.getResult())) {
                    Log.v("获取成功", "");
                } else {
                    Log.v("获取失败", "");
                }
            }
        });
    }

    private void setjjdate() {
        jjlist.clear();
        JJInfo jinfo = new JJInfo();
        jinfo.setName("" + EmmApplication.getUserName());
        jinfo.setNumber("100");
        jinfo.setPid(EmmApplication.getUserId());
        jjlist.add(jinfo);

        jjadapter = new JJAdapter(jjlist, NewSubscribeActivity.this, getconsultan.getConsultantList());
        jj_list.setAdapter(jjadapter);
        jjadapter.SetType(0);
    }

    JJAdapter jjadapter;

    ArrayList<JJInfo> jjlist = new ArrayList<NewSignedActivity.JJInfo>();

    /**
     * <p>
     * <b>Title：</b> 选项框
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param listname
     * @param title
     * @param ed
     * @param type
     * @author tangxin
     * @date 2016年12月7日 下午4:05:24
     */
    @SuppressLint("WrongConstant")
    public void setZpPoPu(final List<String> listname, String title, final EditText ed, final int type) {
        view = LayoutInflater.from(NewSubscribeActivity.this).inflate(R.layout.popu_zp, null);
        popu = new PopupWindow(view, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
        popu.setFocusable(true);
        // EmmApplication.setNumberLog(NewSubscribeActivity.this, 0.5f);//
        // 改变popupwindow范围外的屏幕亮度
        popu.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popu.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popu.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        popu.showAsDropDown(view, 0, 0);
        popu.setFocusable(true);
        popu.setOutsideTouchable(true);
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    popu.dismiss();
                    EmmApplication.setLog(NewSubscribeActivity.this);
                }
                return false;
            }
        });
        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                popu.dismiss();
                EmmApplication.setLog(NewSubscribeActivity.this);
            }
        });

        PickerView select_pick = (PickerView) view.findViewById(R.id.select_pick);

        selectName = listname.get(0);

        TextView shuerbtn = (TextView) view.findViewById(R.id.shuerbtn);
        RelativeLayout relative_all = (RelativeLayout) view.findViewById(R.id.relative_all);

        ImageView dis_btn = (ImageView) view.findViewById(R.id.dis_btn);
        dis_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu.dismiss();
                EmmApplication.setLog(NewSubscribeActivity.this);
            }
        });
        TextView title_select = (TextView) view.findViewById(R.id.title_select);

        title_select.setText(title);

        select_pick.setData(listname);
        select_pick.setOnSelectListener(new onSelectListener() {
            @Override
            public void onSelect(String text, int id) {
                selectName = text;
                SelectID = id;
                if (type == 1) {
                    agentId = id;
                }
            }
        });
        select_pick.setSelected(0);
        shuerbtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 确定
                popu.dismiss();
                EmmApplication.setLog(NewSubscribeActivity.this);
                ed.setText(selectName);
            }
        });
        relative_all.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }

    // 【客户家庭成员信息】
    public class CustomerFamilyListInfo {
        private String memberName;// 客户姓名
        private String documentType;// 证件类型
        private String documentNumber;// 证件号码

        public String getMemberName() {
            return memberName;
        }

        public void setMemberName(String memberName) {
            this.memberName = memberName;
        }

        public String getDocumentType() {
            return documentType;
        }

        public void setDocumentType(String documentType) {
            this.documentType = documentType;
        }

        public String getDocumentNumber() {
            return documentNumber;
        }

        public void setDocumentNumber(String documentNumber) {
            this.documentNumber = documentNumber;
        }
    }

    /**
     * 客户详情
     */
    GetCustomerDetail details;

    /**
     * <p>
     * <b>Title：</b> 客户详情
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param customerId
     * @author tangxin
     * @date 2016年12月7日 下午4:05:49
     */
    private void getCustomerDetail(String customerId) {
        EmmApplication.updateUrl("getCustomerDetail");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("customerId", customerId);
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getCustomerDetail-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.hideDialogForLoading();
                Loading.showDialogForLoading(NewSubscribeActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                details = JSONObject.parseObject(resData.toString(), GetCustomerDetail.class);
                if ("1".equals(details.getResult())) {
                    Log.v("获取成功", "");

                    customerName_view.setText(details.getCustomerName());
                    zj_type.setText(details.getPeDocumentType());
                    peDocumentNumber_view.setText(details.getPeDocumentNumber());
                    customerPhone_view.setText(details.getCustomerPhone());
                    // String str1 = "";
                    // if ("".equals(details.getPeDomicilePlace()) ||
                    // "null".equals(details.getPeDomicilePlace())
                    // || TextUtils.isEmpty(details.getPeDomicilePlace())) {
                    // str1 = "";
                    // } else {
                    // str1 = details.getPeDomicilePlace() + "-";
                    // }
                    String str2 = "";
                    if ("".equals(details.getPeContactAddress()) || "null".equals(details.getPeContactAddress())
                            || TextUtils.isEmpty(details.getPeContactAddress())) {
                        str2 = "";
                    } else {
                        str2 = details.getPeContactAddress();
                    }
                    select_address.setText(str2);
                    pePostcode_view.setText(details.getPePostcode());

                    if ("商业按揭".equals(details.getRqPaymentMethod())) {
                        pay_type.setText("商业贷款");
                    } else if ("公积金按揭".equals(details.getRqPaymentMethod())) {
                        pay_type.setText("公积金贷款");
                    } else {
                        pay_type.setText(details.getRqPaymentMethod());
                    }
                } else {
                    EmmApplication.T(details.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + details.getErrorCode().toString() + "errorMsg:"
                                + details.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("新增认筹+客户详情，错误信息获取空指针异常", "");
                    }
                }
            }
        });
    }

    /**
     * <p>
     * <b>Title：</b> 填充数据
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午4:07:42
     */
    private void SetDataView() {
        GetSubscribeDetail getsubscribe = EmmApplication.getsubscribe;

        if (EmmApplication.isNull(getsubscribe.getRealAmount())) {
            realAmount_linearlayout.setVisibility(View.VISIBLE);
            realAmount_view.setText(getsubscribe.getRealAmount());
        } else {
            realAmount_linearlayout.setVisibility(View.GONE);
        }

        if (EmmApplication.isNull(getsubscribe.getFloorType())) {
            PriceType = Integer.valueOf(getsubscribe.getFloorType()).intValue();
        }

        Hdnumber = getsubscribe.getDiscountRate();
        if (false == EmmApplication.isNull(Hdnumber)) {
            Hdnumber = "0";
        }

        String sttt;
        try {
            sttt = getsubscribe.getBusReturnType();
        } catch (NullPointerException e) {
            sttt = "0";
        }
        if ("1".equals(sttt)) {// 认筹
            realAmount_linearlayout.setVisibility(View.VISIBLE);
            realAmount_name_view.setText("已收认筹金");
            realAmount_view.setText(getsubscribe.getRealAmount());
        } else if ("2".equals(sttt)) {// 认购
            realAmount_linearlayout.setVisibility(View.VISIBLE);
            realAmount_name_view.setText("已收认购金");
            realAmount_view.setText(getsubscribe.getRealAmount());
        } else {
            realAmount_linearlayout.setVisibility(View.GONE);
        }

        Log.v(TAG, "DiscountRate:" + Hdnumber);

        FrdID = getsubscribe.getRoomId();
        jjlist.clear();
        if (null != getsubscribe.getDealCategoryList() && getsubscribe.getDealCategoryList().size() > 0) {
            for (int i = 0; i < getsubscribe.getDealCategoryList().size(); i++) {
                JJInfo jinfo = new JJInfo();
                jinfo.setName(getsubscribe.getDealCategoryList().get(i).getRelationAgentName());
                jinfo.setNumber(getsubscribe.getDealCategoryList().get(i).getProportionCommission());
                jinfo.setPid(getsubscribe.getDealCategoryList().get(i).getRelationAgentId());
                jjlist.add(jinfo);
            }
            jjadapter = new JJAdapter(jjlist, NewSubscribeActivity.this, getconsultan.getConsultantList());
            jj_list.setAdapter(jjadapter);
            jjadapter.SetType(0);
        }

        rengou_code.setText(getsubscribe.getSubscribeCode());

        housing_btn.setText(getsubscribe.getSubscribeHouses());

        valuation_area.setText(getsubscribe.getCalculateArea());

        folding_front_unit_price.setText(getsubscribe.getDiscountPrice());

        discountTotalPrice_view.setText(getsubscribe.getDiscountTotalPrice());

        customerName_view.setText(getsubscribe.getCustomerName());

        zj_type.setText(getsubscribe.getDocumentType());

        peDocumentNumber_view.setText(getsubscribe.getDocumentNumber());

        customerPhone_view.setText(getsubscribe.getMobile());

        select_address.setText(getsubscribe.getMailPost());

        pePostcode_view.setText(getsubscribe.getPostcode());

        if (null != getsubscribe.getCustomerFamilyList() && getsubscribe.getCustomerFamilyList().size() > 0) {
            if (null != list) {
                list.clear();
            } else {
                list = new ArrayList<NewClassKehuModel>();
            }

            for (int i = 0; i < getsubscribe.getCustomerFamilyList().size(); i++) {
                NewClassKehuModel m = new NewClassKehuModel();
                m.setCode(getsubscribe.getCustomerFamilyList().get(i).getDocumentNumber());
                m.setName(getsubscribe.getCustomerFamilyList().get(i).getMemberName());
                m.setNumber("" + (i + 1));
                list.add(m);
            }
            adapter = new NewFromAdapter(NewSubscribeActivity.this, list);
            kehuxinxi.setAdapter(adapter);
            adapter.SetType(0);
        }
        try {
            discountAmount_all_view.setText(getsubscribe.getDiscountAfterAmount());
        } catch (Exception e) {
            discountAmount_all_view.setText("");
        }
        discountAmount_view.setText(getsubscribe.getDiscountAmount());

        discountRate_view.setText(getsubscribe.getAddDiscountRate());

        youhui_view.setText(getsubscribe.getPreferentialReasons());

        discountNote_view.setText(getsubscribe.getDiscountNote());

        contractPrice_view.setText(getsubscribe.getContractPrice());

        contractAmount_view.setText(getsubscribe.getContractAmount());

        depositReceivable_view.setText(getsubscribe.getDepositReceivable());

        p_from_time.setText(getsubscribe.getDueTime());

        pay_type.setText(getsubscribe.getPaymentMethod());

        cj_type.setText(getsubscribe.getDealCategory());

        if ("推荐成交".equals(getsubscribe.getDealCategory())) {
            reference_linear_layout.setVisibility(View.VISIBLE);
            referenceName.setText(getsubscribe.getReferenceName());
            referenceProportion.setText(getsubscribe.getReferenceProportion());
        } else {
            reference_linear_layout.setVisibility(View.GONE);
        }

        p_jjrmine.setText(getsubscribe.getAgentId());

        rg_times.setText(getsubscribe.getSubscribeDate());

        remark_view.setText(getsubscribe.getRemark());

        if (null != getsubscribe.getImageList() && getsubscribe.getImageList().size() > 0) {
            for (int i = 0; i < getsubscribe.getImageList().size(); i++) {
                AddpirModel a = new AddpirModel();
                a.setIsnet("2");
                a.setType("1");
                a.setPath("" + getsubscribe.getImageList().get(i).getSmallUrl());
                ap.add(0, a);
                ImageItem ima = new ImageItem();
                ima.type = "2";
                ima.imageId = EmmApplication.geTimes() + i;
                ima.sourcePath = getsubscribe.getImageList().get(i).getSmallUrl();
                EmmApplication.pir.add(ima);
                ap2.add(a);
            }
        }

        padapter.SetDate(ap);

        if ("0".equals(getsubscribe.getAnnexNum()) || null == getsubscribe.getAnnexNum()
                || "null".equals(getsubscribe.getAnnexNum())) {
            annex_layout.setVisibility(View.GONE);
        } else {
            annexNum_view.setText("存在以下" + getsubscribe.getAnnexNum() + "个非图片附件，请通过电脑端查看  ");
            annex_layout.setVisibility(View.VISIBLE);
            AnnexAdapter annexAdapter = new AnnexAdapter(NewSubscribeActivity.this, getsubscribe.getAnnexList());
            annexList_list.setAdapter(annexAdapter);
        }

    }

    /**
     * 证件类型
     */
    ArrayList<RqBusNumList> DocumentType;

    /**
     * 字典数据源
     */
    NewGetDictionaryList getdiction;

    /**
     * <p>
     * <b>Title：</b> 查询字典列表接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午4:08:25
     */
    private void getDictionaryList() {
        EmmApplication.updateUrl("getDictionaryListByProjectId");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("busNumType", "12");
        map.put("busNum", "01");
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getDictionaryList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v(TAG, "content==:" + content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }
                getdiction = JSONObject.parseObject(resData.toString(), NewGetDictionaryList.class);
                if ("1".equals(getdiction.getResult())) {
                    DocumentType = getdiction.getTypeMap().getDocumentType();
                } else {
                    EmmApplication.T(getdiction.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + getdiction.getErrorCode().toString() + "errorMsg:"
                            + getdiction.getErrorMsg().toString());
                }
            }
        });
    }

    /**
     * 异步处理请求事件
     */
    class RecordTaskUpdate extends AsyncTask<Void, Integer, Void> {

        String auditStatus;// 0代表保存，1，代表提交审核

        int type = 0;// 0代表新增认购或者有房认筹转认购，1代表其他情况

        public RecordTaskUpdate(String auditStatus, int type) {
            this.auditStatus = auditStatus;
            this.type = type;
        }

        @Override
        protected Void doInBackground(Void... arg0) {
            ArrayList<ImageListInfo> contentList_ = new ArrayList<ImageListInfo>();
            if (EmmApplication.pir.size() > 0) {
                for (int i = 0; i < EmmApplication.pir.size(); i++) {
                    if ("1".equals(EmmApplication.pir.get(i).type)) {
                        ImageListInfo content = new ImageListInfo();
                        content.setSignedUrl(EmmApplication.setPatchRtString(EmmApplication.pir.get(i).sourcePath));
                        content.setHeadType(".jpg");
                        contentList_.add(content);
                    }
                }
            } else {
                for (int m = 0; m < ap2.size(); m++) {
                    ImageListInfo content = new ImageListInfo();
                    content.setSignedUrl(ap2.get(m).getPath());
                    content.setHeadType("1");
                    contentList_.add(content);
                }
            }

            for (int m = 0; m < ap2.size(); m++) {
                int p = 0;
                for (int u = 0; u < EmmApplication.pir.size(); u++) {
                    if ("2".equals(EmmApplication.pir.get(u).type)) {
                        if (ap2.get(m).getPath().equals(EmmApplication.pir.get(u).sourcePath)) {
                            p++;
                        }
                    }
                }
                if (p > 0) {
                    ImageListInfo content = new ImageListInfo();
                    content.setSignedUrl(ap2.get(m).getPath());
                    content.setHeadType("0");
                    contentList_.add(content);
                } else {
                    ImageListInfo content = new ImageListInfo();
                    content.setSignedUrl(ap2.get(m).getPath());
                    content.setHeadType("1");
                    contentList_.add(content);
                }
            }

            AddSubscribe(contentList_, auditStatus, type);
            return null;
        }

        // 当在上面方法中调用publishProgress时，该方法触发,该方法在I线程中被执行
        protected void onProgressUpdate(Integer... progress) {
        }

        protected void onPostExecute(Void result) {
        }

        protected void onPreExecute() {
        }

    }

    /**
     * 菜单
     */
    public View view3;

    /**
     * 菜单
     */
    public PopupWindow popu_phone;

    /**
     * 拍照图片路径
     */
    private Uri mImageCaptureUri;

    private static final int PICK_FROM_CAMERA = 1;
    private static final int SELECT_CUSTOMER = 2;

    /**
     * <p>
     * <b>Title：</b> 点击添加图片按钮后的弹出框
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:32:06
     */
    @SuppressLint("WrongConstant")
    public void popu() {
        view3 = LayoutInflater.from(NewSubscribeActivity.this).inflate(R.layout.item_popupwindow, null);
        popu_phone = new PopupWindow(view3, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);

        popu_phone.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popu_phone.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        popu_phone.showAtLocation(view3, Gravity.BOTTOM, 0, 0);
        popu_phone.showAsDropDown(view3, 0, 0);
        popu_phone.setFocusable(true);
        popu_phone.setOutsideTouchable(true);
        view3.setFocusable(true);
        view3.setFocusableInTouchMode(true);

        view3.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    popu_phone.dismiss();
                }
                return false;
            }
        });

        view3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
            }
        });

        // 拍照
        Button item_popupwindows_camera = (Button) view3.findViewById(R.id.item_popupwindows_camera);
        // 相册
        Button item_popupwindows_Photo = (Button) view3.findViewById(R.id.item_popupwindows_Photo);
        // 取消
        Button item_popupwindows_cancel = (Button) view3.findViewById(R.id.item_popupwindows_cancel);

        item_popupwindows_cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
                EmmApplication.setLog(NewSubscribeActivity.this);
            }
        });
        item_popupwindows_camera.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popu_phone.dismiss();
                Album.camera(activity).start(PICK_FROM_CAMERA);
            }
        });
        item_popupwindows_Photo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EmmApplication.bitmap = null;
                popu_phone.dismiss();
                EmmApplication.setData("Picture", "1");
                EmmApplication.IsMoreSelect = true;
                startActivity(new Intent(NewSubscribeActivity.this, ImageBucketChooseActivity.class));
            }
        });
    }

    /**
     * 回调方法
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.w("a", +requestCode + "resultCode===" + resultCode + "RESULT_OK======" + RESULT_OK);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case PICK_FROM_CAMERA:
                String path = Album.parseResult(data).get(0);
                Log.w("a", "拍照:+>" + path);

                ImageItem item = new ImageItem();
                item.sourcePath = path;
                item.imageId = "1101841324";
                EmmApplication.pir.add(item);

                SetImage();

                break;
            case 0:
                System.out.println("相册");
                break;
            case SELECT_CUSTOMER:
                GetCustomerList.CustomerList customer = (GetCustomerList.CustomerList) data.getSerializableExtra(CustomerFragment.CUSTOMER);
                customerId = customer.getCustomerId();
                getCustomerDetail(customerId);
                customerName_view.setText(customer.getCustomerName());
                customerPhone_view.setText(customer.getMobile());
                break;
            default:
                break;
        }
    }

}
